# coding:utf-8
"""
    @project: automated_testing_platform
    @Author：caicaizi
    @file： run_case.py
    @date：2023/6/9 9:28
"""
from openpyxl import load_workbook, Workbook
from utils.excel.excel_executor import ExcelExecutor
from utils.web_testing_utils.base_web_driver import BaseWebDriver



def write_test_result(sheet, row_num, col_num, test_result, error_info, pic_path):
    try:
        pass
    except Exception as e:
        raise e


def run_case():
    try:
        filepath = 'D:/项目/automated-testing-platform/automated-testing-platform-server/automated_testing_platform/utils/excel/demo.xlsx'
        ee = ExcelExecutor()
        wb = ee.load_workbook(filepath)
        sheet = ee.get_sheet_by_name('搜索')
        step_num = ee.get_max_row_num(sheet)
        driver = BaseWebDriver()
        for i in range(2, step_num + 1):
            step = ee.get_row(sheet, i)
            order = step[2].value
            by = step[3].value
            pattern = step[4].value
            value = step[5].value
            expression_str = ''
            if order and by and pattern and value:
                expression_str = f'driver.{order}(by, pattern, value)'
            elif order and by and pattern and value is None:
                expression_str = f'driver.{order}(by, pattern)'
            elif order and by is None and pattern and value is None:
                expression_str = f'driver.{order}(pattern)'
            elif order and by is None and pattern is None and value is None:
                expression_str = f'driver.{order}()'
            elif order and by is None and pattern is None and value:
                expression_str = f'driver.{order}(value)'
            try:
                exec(expression_str.strip())
                # print(expression_str)
            except Exception as e:
                raise e
        driver.quit_driver()
    except Exception as e:
        raise e


run_case()